import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/product",
  },
  //商品模块
  {
    //路由地址
    path: "/product",
    //路由地址对应组件
    component: () => import("@/views/product/index.vue"),
    redirect: "/product/list",
    //配置子路由
    children: [
      {
        path: "list",
        name:'list',
        //缓存次组件
        meta:{
          keepAlive:true,
        },
        component: () => import("@/views/product/children/list.vue"),
      },
      {
        path: "detail/:productId",
        component: () => import("@/views/product/children/detail.vue"),
      },
    ],
  },
  //购物车模块
  {
    path: "/cart",
    component: () => import("@/views/cart/index.vue"),
  },
  //我的模块
  {
    path: "/my",
    component: () => import("@/views/my/index.vue"),
    //配置子路由
    redirect: "/my/person",
    children: [
      {
        path: "person",
        component: () => import("@/views/my/children/person.vue"),
      },
      {
        path: "set",
        component: () => import("@/views/my/children/set.vue"),
      },
    ],
  },
  //登录模块
  {
    path: "/account",
    component: () => import("@/views/account/index.vue"),
    //配置子路由
    redirect: "/account/login",
    children: [
      {
        path: "login",
        component: () => import("@/views/account/children/login.vue"),
      },
      {
        path: "register",
        component: () => import("@/views/account/children/register.vue"),
      },
    ],
  },

  //分类模块
  {
    path: "/type",
    component: () => import("@/views/type/index.vue"),
  },
  //订单模块
  {
    path: "/order",
    component: () => import("@/views/order/index.vue"),
    //配置子路由
    children: [
      {
        path: "list",
        component: () => import("@/views/order/children/list.vue"),
      },
      {
        path: "detail",
        component: () => import("@/views/order/children/detail.vue"),
      },
      {
        path: "verify",
        component: () => import("@/views/order/children/verify.vue"),
      },
      {
        path: "pay",
        component: () => import("@/views/order/children/pay.vue"),
      },
    ],
  },
  //地址模块
  {
    path:'/address',
    component:() => import('@/views/address/index'),
    children:[
      {
        path: "list",
        component: () => import("@/views/address/children/list.vue"),
      },
      {
        path: "detail",
        component: () => import("@/views/address/children/detail.vue"),
      },
      
    ]
  },
  {
    path: "/demo",
    component: () => import("@/views/demo/index.vue"),
  },
  {
    path: "*",
    component: () => import("@/components/NotFound"),
  },
];

const router = new VueRouter({
  // mode: "history", // 默认hash
  scrollBehavior: () => ({
    y: 0,
  }),
  routes,
});

export default router;
